*********************************************************************************
*** Appendix A7
*********************************************************************************

* Project: 	International threats and European defense
* Authors: 	Matthias Mader
* Date:		March 2023	

* Data: VW Project, Pane-European survey (W1)

*********************************************************************************

*** Setup

	clear
	set more off            						// Disable partitioned output
	set dp period									// Use comma instead of dot for decimals
	set linesize 80         						// Line size limit to make output more readable
	macro drop _all         						// clear all macros
	set scheme plotplainblind, permanent				// set graph scheme, e.g., cleanplots, plottig, plotplainblind, burd3, s1mono
	graph set window fontface "Times New Roman"		// set font in graphs | "Arial" | "Times New Roman"


*** Table A7.1
	
	use DATA_clean, clear

	*Row 1
	reg csdp_wouldlike c.threat_ind2##c.eurid i.QCOUNTRY female age ib2.education iso comp mili
	margins, dydx(threat_ind2)
	margins, dydx(threat_ind2) at(eurid=(0 1))
	*Column 4, row 1: Interaction term (c.threat_ind2#c.feel_EU) in regression table

	*** Rows 2, 3
	reg csdp_wouldlike c.threat_ind2##c.eurid##c.quizr i.QCOUNTRY female age i.education iso comp mili
	margins, dydx(threat_ind2) at(quiz=(0 1))
	margins, dydx(threat_ind2) at(eurid=(0 1) quiz=(0))
	margins, dydx(threat_ind2) at(eurid=(0 1) quiz=(1))


*** Figure A7.1
	
	use DATA_clean, clear

	*Main effect of threat perceptions
	reg csdp_wouldlike c.threat_ind2 c.eurid i.QCOUNTRY female age ib2.education iso comp mili
	estimates store m1
	margins, at(threat_ind2=(0 (.025) 1))
	marginsplot,  ///
		name(g1, replace) ///
		recast(scatter) ///
		plotopts(mcolor(none))  ///
		ciopts(recast(rbar) barwidth(0.01)) ///
		xtitle("Threat perception", size(large)) xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
		ytitle("Support for integration", size(large)) yscale(range(0 1)) ylabel(0 (0.2) 1, labsize(large)) ///	
		title("") ///
		legend(off)

	*Support for European defence and security integration, by threat perception and attachment to Europe
	reg csdp_wouldlike c.threat_ind2##c.eurid i.QCOUNTRY female age ib2.education iso comp mili
	estimates store m2
	margins, at(threat_ind2=(0 (.025) 1) eurid=(0 1))
	marginsplot,  ///
		name(g2, replace) ///
		recast(scatter) ///
		plot1opts(mcolor(none)) plot2opts(mcolor(none)) ///
		text(0.85 -0.01 "Strong attachment to Europe", color(gs9) place(right) size(large)) ///
		text(0.40 -0.01  "No attachment to Europe", color(gs0) place(right) size(large)) ///
		ciopts(recast(rbar) barwidth(0.01)) ///
		xtitle("Threat perception", size(large)) xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
		ytitle("Support for integration", size(large)) yscale(range(0 1)) ylabel(0 (0.2) 1, labsize(large)) ///	
		title("") ///
		legend(off)

	*Support for European defence and security integration among politically unsophisticated, by threat perception and attachment to Europe
	reg csdp_wouldlike c.threat_ind2##c.eurid##c.quizr i.QCOUNTRY female age ib2.education iso comp mili
	estimates store m3
	margins, at(threat_ind2=(0 (.025) 1) eurid=(0 1) quizr=(0))
	marginsplot,  ///
		name(g3, replace) ///
		recast(scatter) ///
		plot1opts(mcolor(none)) plot2opts(mcolor(none)) ///
		text(0.83 -0.01 "Unsophisticated, strong attachment to Europe", color(gs9) place(right) size(large)) ///
		text(0.45 -0.01  "Unsophisticated, no attachment to Europe", color(gs0) place(right) size(large)) ///
		ciopts(recast(rbar) barwidth(0.01)) ///
		xtitle("Threat perception", size(large)) xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
		ytitle("Support for integration", size(large)) yscale(range(0 1)) ylabel(0 (0.2) 1, labsize(large)) ///	
		title("") ///
		legend(off)


	*Support for European defence and security integration among politically sophisticated, by threat perception and attachment to Europe
	reg csdp_wouldlike c.threat_ind2##c.eurid##c.quizr i.QCOUNTRY female age ib2.education iso comp mili
	margins, at(threat_ind2=(0 (.025) 1) eurid=(0 1) quizr=(1))
	marginsplot,  ///
		name(g4, replace) ///
		recast(scatter) ///
		plot1opts(mcolor(none)) plot2opts(mcolor(none)) ///
		text(0.86 -0.01 "Sophisticated, strong attachment to Europe", color(gs9) place(right) size(large)) ///
		text(0.40 -0.01  "Sophisticated, no attachment to Europe", color(gs0) place(right) size(large)) ///
		ciopts(recast(rbar) barwidth(0.01)) ///
		xtitle("Threat perception", size(large)) xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
		ytitle("Support for integration", size(large)) yscale(range(0 1)) ylabel(0 (0.2) 1, labsize(large)) ///	
		title("") ///
		legend(off)


*** Table A7.2

	use Pan_EuropeanData_CLEAN.dta, clear

	*column 1
	forvalues val = 1/25 {
	reg csdp_wouldlike c.threat_ind2 c.eurid female age ib2.education iso comp mili if QCOUNTRY==`val'
	estimates store m`val'
}
	*Table 2, columns 2, 3
	forvalues val = 1/25 {
	reg csdp_wouldlike c.threat_ind2##c.eurid female age ib2.education iso comp mili natid if QCOUNTRY==`val'
	estimate store m`val'
}
	forvalues val = 1/25 {
	estimate restore m`val'
	margins, dydx(threat_ind2) at(eurid=(0 1))
}


*** Figure A7.2

	use Pan_EuropeanData_CLEAN.dta, clear

	*Austria for labels
	reg csdp_wouldlike c.threat_ind2##c.eurid##i.QCOUNTRY female age education iso comp mili
	foreach val in 1 {
	local v : label (QCOUNTRY) `val'
	margins, at(threat_ind2=(0 (.025) 1) eurid=(0 1) QCOUNTRY=(`val'))
	marginsplot,  ///
		name(c`val', replace) ///
		recast(scatter) ///
		plot1opts(mcolor(none)) plot2opts(mcolor(none)) ///
		text(.90 -0.01 "Strong attachment to Europe", color(gs9) place(right) size(large)) ///
		text(0.37 -0.01  "No attachment to Europe", color(gs0) place(right) size(large)) ///
		ciopts(recast(rbar) barwidth(0.01)) ci1opts(color(gs0) alcolor(none)) ci2opts(color(gs9%80) alcolor(none)) ///
		xlab(, nogrid labcolor(white)) ///
		graphregion(margin(l=-6 r=-5 t=-4 b=-4)) ///
		xtitle("") xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
		ytitle("") yscale(range(0 1)) ylabel(0 (0.2) 1, labsize(large)) ///	
		title("") ///
		text(.1 1 "`v'", size(vlarge) place(left)) ///
		legend(off)
}
	*All other countries
	reg csdp_wouldlike c.threat_ind2##c.eurid##i.QCOUNTRY female age education iso comp mili
	foreach val in 2 3 4 5 7 8 9 10 12 13 14 15 17 18 19 20 {
	local v : label (QCOUNTRY) `val'
	margins, at(threat_ind2=(0 (.025) 1) eurid=(0 1) QCOUNTRY=(`val'))
	marginsplot,  ///
		name(c`val', replace) ///
		recast(scatter) ///
		plot1opts(mcolor(none)) plot2opts(mcolor(none)) ///
		ciopts(recast(rbar) barwidth(0.01)) ci1opts(color(gs0) alcolor(none)) ci2opts(color(gs9%80) alcolor(none)) ///
		ylab(, nogrid labcolor(white)) ///
		xlab(, nogrid labcolor(white)) ///
		graphregion(margin(l=-6 r=-5 t=-4 b=-4)) ///
		xtitle("") xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
		ytitle("") yscale(range(0 1)) ylabel(0 (0.2) 1, labsize(large)) ///	
		title("") ///
		text(.1 1 "`v'", size(vlarge) place(left)) ///
		legend(off)
}
	*All other countries
	reg csdp_wouldlike c.threat_ind2##c.eurid##i.QCOUNTRY female age education iso comp mili
	foreach val in 6 11 16 {
	local v : label (QCOUNTRY) `val'
	margins, at(threat_ind2=(0 (.025) 1) eurid=(0 1) QCOUNTRY=(`val'))
	marginsplot,  ///
		name(c`val', replace) ///
		recast(scatter) ///
		plot1opts(mcolor(none)) plot2opts(mcolor(none)) ///
		ciopts(recast(rbar) barwidth(0.01)) ci1opts(color(gs0) alcolor(none)) ci2opts(color(gs9%80) alcolor(none)) ///
		ylab(, nogrid) ///
		xlab(, nogrid labcolor(white)) ///
		graphregion(margin(l=-6 r=-5 t=-4 b=-4)) ///
		xtitle("") xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
		ytitle("") yscale(range(0 1)) ylabel(0 (0.2) 1, labsize(large)) ///	
		title("") ///
		text(.1 1 "`v'", size(vlarge) place(left)) ///
		legend(off)
}
	*All other countries
	reg csdp_wouldlike c.threat_ind2##c.eurid##i.QCOUNTRY female age education iso comp mili
	foreach val in 21 {
	local v : label (QCOUNTRY) `val'
	margins, at(threat_ind2=(0 (.025) 1) eurid=(0 1) QCOUNTRY=(`val'))
	marginsplot,  ///
		name(c`val', replace) ///
		recast(scatter) ///
		plot1opts(mcolor(none)) plot2opts(mcolor(none)) ///
		ciopts(recast(rbar) barwidth(0.01)) ci1opts(color(gs0) alcolor(none)) ci2opts(color(gs9%80) alcolor(none)) ///
		ylab(, nogrid) ///
		xlab(, nogrid) ///
		graphregion(margin(l=-6 r=-5 t=-4 b=-4)) ///
		xtitle("") xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
		ytitle("") yscale(range(0 1)) ylabel(0 (0.2) 1, labsize(large)) ///	
		title("") ///
		text(.1 1 "`v'", size(vlarge) place(left)) ///
		legend(off)
}
	*All other countries
	reg csdp_wouldlike c.threat_ind2##c.eurid##i.QCOUNTRY female age education iso comp mili
	foreach val in 22 23 24 25 {
	local v : label (QCOUNTRY) `val'
	margins, at(threat_ind2=(0 (.025) 1) eurid=(0 1) QCOUNTRY=(`val'))
	marginsplot,  ///
		name(c`val', replace) ///
		recast(scatter) ///
		plot1opts(mcolor(none)) plot2opts(mcolor(none)) ///
		ciopts(recast(rbar) barwidth(0.01)) ci1opts(color(gs0) alcolor(none)) ci2opts(color(gs9%80) alcolor(none)) ///
		ylab(, nogrid labcolor(white)) ///
		xlab(, nogrid) ///
		graphregion(margin(l=-6 r=-5 t=-4 b=-4)) ///
		xtitle("") xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
		ytitle("") yscale(range(0 1)) ylabel(0 (0.2) 1, labsize(large)) ///	
		title("") ///
		text(.1 1 "`v'", size(vlarge) place(left)) ///
		legend(off)
}
	graph combine c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 c25, l1("Support for security/defence integration", size(small)) b1(Threat perception, size(small)) xcommon ycommon


